//3 1
//3 15 ()
//1 20 (2)
//2 10 (3)
let count = 0

function fn(arr, target) {
  arr.forEach((item1, i) => {
    item1.forEach((item2, j) => {
      if (arr[i][0] === target && j === 0) {
        count += arr[i][j+1]

        if (arr[i][j+2] !== -1) {
          fn(arr, arr[i][j+2])
        }
      }
    })
  })
}

const arr = [
  [3,15,-1],
  [1,20,2],
  [2,10,3],
]
fn(arr, 1)
console.log(count)


// 从 '3 15 (2)'中提取出3 15 2, 结果实例为[3,15,2]
const str = '3 15 (2)'
const reg = /\d+/g
const arr1 = str.match(reg)
console.log(arr1.map(item => Number(item)))
